<admintpl file="header" />
</head>
<body>
<style>
input[type="checkbox"]{ margin: 0;}
    ul, ol {
        list-style: none outside none;
    }
    em.zt {
        font-size: 0;
        line-height: 0;
        width: 0;
        height: 0;
        display: inline-block;
        padding: 0;
        border: 4px solid;
        border-color: #333 transparent transparent transparent;
        border-style: solid dashed dashed dashed;
    }
    .ks-stdmod-body label {
        display: inline-block;
    }
</style>
<link rel="stylesheet" href="__TMPL__Public/assets/css/transport.css"/>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('Activity/index')}">活动管理</a></li>
            <li><a href="{:U('Activity/add')}">添加活动</a></li>
            <li class="active"><a>修改活动</a></li>
        </ul>
        <form action="{:U('Activity/edit_activity')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
            <div class="row-fluid">
                <div class="span9">
                    <table class="table table-bordered">

                        <tr>
                            <th width="90">名称</th>
                            <td>
                                <input type="hidden" name="id" value="{$event.id}" />
                                <input type="text" name="event_name" id="title" required value="{$event.event_name}" placeholder="请输入名称" maxlength="16"  autocomplete="off" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>最长16个汉字、不可为空
                            </td>
                        </tr>
                        <tr>
                            <th>开始日期</th>
                            <td>
                                <input type="text" name="start_at" class="js-datetime" value="{$event.start_at}" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <th>结束日期</th>
                            <td>
                            	<input type="text" name="end_at" class="js-datetime" value="{$event.end_at}" autocomplete="off">
							</td>
                        </tr>
                        <tr>
                            <th>权重(中奖率)</th>
                            <td>
                            	<input type="text" name="event_weight_factor" required placeholder="活动权重" value="{$event.event_weight_factor}"  maxlength="4" autocomplete="off" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>最长4位数字
                            </td>
                        </tr>
                        <tr data-group="n1">
                            <th>选择区域</th>
                            <td class="cell-area">
                            <a class="acc_popup edit J_EditArea" title="编辑运送区域" area-haspopup="true"
                               area-controls="J_DialogArea" entype="J_EditArea" data-acc="event:enter"
                               href="JavaScript:void(0);">地域投放</a>
                                <span class="area-group">
                                    <input class="J_BatchField" style="width:15px;display:none" type="checkbox" name="es_n1">
                                    <p>{:implode(',',$event_names)}</p>
                                </span>
                                 <input type="hidden" value="{:implode(',',$event_areas)}" name="areas[]">
                            </td>
                        </tr>
                        <tr>
                            <th>选择群组<input type="checkbox" name="group" value="1" style="margin:0 2px 0;"<if condition="count($event_groups)"> checked </if>></td>
                            <td>
                            	<div id="groupbox" <if condition="!count($event_groups)"> style="display:none" </if>>
                                <foreach name="groups" item="vo">
                                    <label style="float: left; margin-right:10px;">
                                        <input type="checkbox" name="groups[]" value="{$vo.id}"
                                        <foreach name="event_groups" item="egroup">
                                            <if condition="$vo['id'] eq $egroup['area_id']">
                                                checked
                                            </if>
                                        </foreach>
                                        ><span>{$vo.name}</span>
                                    </label>
                                </foreach>
                                <div></div>
                                <foreach name="customGroups" item="vo">
                                    <label style="float: left; margin-right:10px;">
                                        <input type="checkbox" name="customGroups[]" value="{$vo.id}"
                                        <foreach name="event_customGroups" item="egroup">
                                            <if condition="$vo['id'] eq $egroup['area_id']">
                                                checked
                                            </if>
                                        </foreach>
                                        ><span>{$vo.area_name}</span>
                                    </label>
                                </foreach>
                            	</div>
                            </td>
                        </tr>
                        <tr>
                            <th>类型</th>
                            <td>
                                <select name="event_type">
                                    <foreach name="eventTypeList" item="vo">
                                        <option value="{$vo.id}"<if condition="$vo['id'] eq $event['event_type']" >selected </if>>{$vo.name}</option>
                                    </foreach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th>摇一摇入口</th>
                            <td>
                                <select id="province" name="wx_page_id">
                                    <option value="0">自定义</option>
                                    <foreach name="wxssap" item="vo">
                                        <option value="{$vo.page_id}" <if condition="$vo['page_id'] eq $event['wx_page_id']" >selected </if>>{$vo.title} - {$vo.description}</option>
                                    </foreach>
                                </select>
                                <input type="text" class="page_th" style="display:none" name="wx_page_id2" value="{$event.wx_page_id}"  maxlength="16" autocomplete="off" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>最长16位数字
                            </td>
                        </tr>
                        <tr>
                            <th>默认总权重<br>(选填)</th>
                            <td>
                                <input type="text" style="width:90px;" name="total_weight" value="{$event.total_weight}"  maxlength="10" onkeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">当活动实时物料总权重低于默认总权重时, 使用默认总权重。
                            </td>
                        </tr>
                        <tr>
                            <th><b>包含物料</b></th>
                            <td colspan=2>
                                <foreach name="event['bind_cards']" item="prize" key="k">
                                    <div>
                                    <foreach name="cardsList" item="vo2">
                                        <if condition="$prize['card_id'] eq $vo2['id']" >
                                            <select name="bind_cards[]">
                                                <foreach name="cardsList" item="vo3">
                                                    <option style="width: 70%;"  <if condition="$prize['card_id'] eq $vo3['id']" >selected </if>  value="{$vo3.id}">{$vo3.card_name}</option>
                                                </foreach>
                                            </select>
                                            <input type="text" style="width:90px;" value="{$prize['weight']}" name="bind_cards_percentage[]" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">
                                            <a href="javascript:void(0);" onclick="delCard(this);" class="btn">删除</a>
                                        </if>
                                    </foreach>
                                    </div>
                                </foreach>
                                <div><a href="javascript:void(0);" onclick="addNewCard(this);">增加物料</a></div>
                            </td>
                        </tr>
                        <tr>
                            <th>介绍</th>
                            <td colspan=2>
								<script type="text/plain" id="content" name="event_intro">{$event.event_intro}</script>
			              	</td>
                        </tr>
                    </table>
                </div>
    		<div class="span3">
				<table width="100%"  cellpadding="2" cellspacing="2" class="table table-bordered">
						<!--<tr><td><b>奖品图片</b><if condition="$event['center_pic']"><a href="{:U('Activity/del_img',array('id'=>$event['id'],'type'=>'center_pic'))}" style="float: right;">删除图片</a></if></td></tr>
						<if condition="$event['center_pic']">
							<tr><td>
								<input type="hidden" name="center_pic" value="{$event.center_pic}" />
								<img src="{$urlimg}{$event.center_pic}">
							</td></tr>
			        	</if>
						<tr><td><input type="file" name="newcenter_pic" id="jpfile" accept="image/*" style="width: 100%;"/></td></tr>
						<tr><td><img src="" id="jpimg"></td></tr>-->
						<tr><td><b>Loding</b><if condition="$event['loding_pic']"><a href="{:U('Activity/del_img',array('id'=>$event['id'],'type'=>'loding_pic'))}" style="float: right;">删除图片</a></if></td></tr>
						<if condition="$event['loding_pic']">
							<tr><td>
								<input type="hidden" name="loding_pic" value="{$event.loding_pic}" />
								<img src="{$urlimg}{$event.loding_pic}">
							</td></tr>
			        	</if>
						<tr><td><input type="file" name="newloding_pic" id="jpfile" accept="image/*" style="width: 100%;"/></td></tr>
						<tr><td><img src="" id="jpimg"></td></tr>
						<tr><td><b>背景图片</b><if condition="$event['bg_pic']"><a href="{:U('Activity/del_img',array('id'=>$event['id'],'type'=>'bg_pic'))}" style="float: right;">删除图片</a></if></td></tr>
						<if condition="$event['bg_pic']">
							<tr><td>
								<input type="hidden" name="bg_pic" value="{$event.bg_pic}" />
								<img src="{$urlimg}{$event.bg_pic}">
							</td></tr>
			        	</if>
						<tr><td><input type="file" name="newbg_pic" id="bgfile" accept="image/*" style="width: 100%;"/></td></tr>
						<tr><td><img src="" id="bgimg"></td></tr>
				</table>
			</div>
            </div>
            <div class="form-actions">
                <button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
                <a class="btn" href="{:U('Activity/index')}">返回</a>
            </div>
        </form>
    </div>
<!-- Dialog -->
<div id="dialog_areas" class="dialog-areas" style="display:none">
    <div class="ks-contentbox">
        <div class="ks-stdmod-header">
            <div class="title">选择区域</div>
        </div>
        <div class="ks-stdmod-body">
            <form method="post" style="margin: 0;">
                <ul id="J_CityList" style="margin: 0;">
                    <!-- BEGIN CITY LIST ----->
                    <li>
                        <div class=" dcity clearfix">
                                <div class="ecity gcity">
                                <span class="group-label">
                                <input type="checkbox" id="J_Group_1" name="areas" class="J_Group js-check-all" value="100000" data-direction="x" data-checklist="js-check-x"/>
                                <label for="J_Group_1" class="checkbox">全国</label>
                                </span>
                                </div>
                                <div class="province-list">
                                <foreach name="province" item="vo">
                                    <div class="ecity">
                                        <span class="gareas">
                                            <input type="checkbox" name="areas" class="J_Province js-check" id="J_Province_{$vo.id}" value="{$vo.code}" data-yid="js-check-y" data-xid="js-check-x"/>
                                            <label for="J_Province_{$vo.id}">{$vo.shortname}</label>
                                            <span class="check_num"/></span>
                                            <em class="zt trigger"></em>
                                            <div class="citys">
                                                <foreach name="city" item="v">
                                                	<if condition="$vo['code'] eq $v['parent_id']" >
	                                                    <span class="areas">
	                                                    <input type="checkbox" name="areas" class="J_City" id="J_City_{$v.id}" value="{$v.code}"/>
	                                                    <label for="J_City_{$v.id}">{$v.name}</label>
	                                                    </span>
                                                	</if>
                                                </foreach>
                                                <p style="text-align: right;">
                                                    <input type="button" class="close_button" value="关闭"/>
                                                </p>
                                            </div>
                                        </span>
                                    </div>
                                </foreach>
                                <span class="group-label">
                   					<button class="J_Submit btn btn-primary" type="button">确定</button>
                                </span>
                                </div>
                        </div>
                    </li>
                    <!--END------>
                </ul>
            </form>
        </div>
        <div class="ks-stdmod-footer">
            <a class="ks-ext-close" href="javascript:void(0)">
                <span class="ks-ext-close-x">X</span>
            </a>
        </div>
    </div>
</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.DIMAUB;
	</script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript" src="__TMPL__Public/assets/js/transport-w.js"></script>
		<script type="text/javascript">
	$("#jpfile").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#jpimg").attr("src", objUrl) ;
		}
	}) ;
	$("#bgfile").change(function(){
		var objUrl = getObjectURL(this.files[0]) ;
		console.log("objUrl = "+objUrl) ;
		if (objUrl) {
			$("#bgimg").attr("src", objUrl) ;
		}
	}) ;
	function getObjectURL(file) {
		var url = null ;
		if (window.createObjectURL!=undefined) { // basic
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}
        function delCard(dom){
            $(dom.parentNode).remove();
        }
        function addNewCard(dom){
            var par = $(dom.parentNode);
            var temp = '<div>\
                <select name="bind_cards[]">\
                <foreach name="cardsList" item="vo"><option value="{$vo.id}">{$vo.card_name}</option></foreach>\
                </select>\
	            <input type="text" style="width:90px;" name="bind_cards_percentage[]" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;">\
                <a href="javascript:void(0);" onclick="delCard(this);" class="btn">删除</a>\
            </div>';
            par.before(temp);
        }

    window.onload=function(){
        var area=document.getElementsByName("area");
        var areasbox=document.getElementById("areasbox");
        for(var i=0;i<area.length;i++){
            area[i].onclick=function(){
                var k=0;
                for(var n=0;n<area.length;n++){
                    if(area[n].checked){
                        k++;
                    }
                }
                if(k==0){
                    areasbox.style.display="none";
                }else{
                    areasbox.style.display="block";
                }
            }
        }
        var group=document.getElementsByName("group");
        var groupbox=document.getElementById("groupbox");
        for(var i=0;i<group.length;i++){
            group[i].onclick=function(){
                var k=0;
                for(var n=0;n<group.length;n++){
                    if(group[n].checked){
                        k++;
                    }
                }
                if(k==0){
                    groupbox.style.display="none";
                }else{
                    groupbox.style.display="block";
                }
            }
        }
    }
    		$(function() {
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				//javascript

				//编辑器
				editorcontent = new baidu.editor.ui.Editor();
				editorcontent.render('content');
				try {
					editorcontent.sync();
				} catch (err) {
				}
				//增加编辑器验证规则
				jQuery.validator.addMethod('editorcontent', function() {
					try {
						editorcontent.sync();
					} catch (err) {
					}
					;
					return editorcontent.hasContents();
				});
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr, $form, options) {

							},
							success : function(data, statusText, xhr, $form) {
								if (data.status) {
									setCookie("refersh_time", 1);
									//添加成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [ {
												name : '继续编辑？',
												callback : function() {
													//reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:U('Activity/index')}";
													return true;
												}
											} ]
										});
									});
								} else {
									isalert(data.info);
								}
							}
						});
					}
				});
			});
			////-------------------------
		});
	$(document).ready(function(){
	   $("#province").change(function(){
		   $("#province option").each(function(i,o){
			   if($(this).attr("selected")){
				   $(".page_th").hide();
				   $(".page_th").eq(i).show();
			   }
		   });
	   });
	   $("#province").change();
	});
	</script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
</body>
</html>
